#include <REGX52.H>
#include <INTRINS.H>
#include "timer0.h"
#include "lcd1602.h"

static char hour = 23;
static char minute = 59;
static char second = 23;
	
void main()
{
	Timer0_Init();
	LCD_Init();
	
	LCD_ShowString(1,1,"Clock:");
	
	while(1)
	{
		LCD_ShowNum(1, 7, hour, 2);
		LCD_ShowChar(1, 9, ':');
		LCD_ShowNum(1, 10, minute, 2);
		LCD_ShowChar(1, 12, ':');
		LCD_ShowNum(1, 13, second, 2);
		
	}
}


/**
  * @brief  定时器0中断处理函数模版
  * @param  无
  * @retval 无
  */
void Timer_Routine(void) interrupt 1
{
	static unsigned int count = 0;

	
	
	count++;
	//P2_0 = 0;
	if(count >= 1000)		//定时器T0每1ms中断一次，进入1000次经过了1s
	{
		second++;
		if(second >= 60){ 
			minute++; 
			second = 0;
		}
		if(minute >= 60){
			hour++; 
			minute = 0;
		}
		if(hour >= 24){
			hour = 0;
		}
		
		count = 0;
	}
	
	//定时器溢出之后需要重新装载
	TH0 = (65535 - 1000) / 256;					//12MHz晶振，12分频
	TL0 = (65535 - 1000) % 256 + 1; 			//
}
